package org.dromara.system.controller.system;


import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.system.domain.vo.SysMessageVo;
import org.dromara.system.domain.bo.SysMessageBo;
import org.dromara.system.service.ISysMessageService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

import java.rmi.ServerException;

/**
 * 系统管理-消息通知
 * 前端访问路由地址为:/system/message
 *
 * @author LionLi
 * @date 2024-03-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/message")
public class SysMessageController extends BaseController {

    private final ISysMessageService sysMessageService;

    /**
     * 查询系统管理-消息通知列表
     */
//    @SaCheckPermission("system:message:list")
    @GetMapping("/list")
    public TableDataInfo<SysMessageVo> list(SysMessageBo bo, PageQuery pageQuery) {
        return sysMessageService.queryPageList(bo, pageQuery);
    }

    /**
     * 新增系统管理-消息通知
     */
    @SaCheckPermission("system:message:add")
    @Log(title = "系统管理-消息通知", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysMessageBo bo) throws ServerException {
        return toAjax(sysMessageService.insertByBo(bo));
    }

    /**
     * 修改系统管理-消息通知
     */
    @SaCheckPermission("system:message:edit")
    @Log(title = "系统管理-消息通知", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysMessageBo bo) {
        return toAjax(sysMessageService.updateByBo(bo));
    }

    /**
     * 删除系统管理-消息通知
     *
     * @param id 主键串
     */
    @SaCheckPermission("system:message:remove")
    @Log(title = "系统管理-消息通知", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R<Void> remove(@PathVariable Long id) {
        return toAjax(sysMessageService.deleteWithValidById(id));
    }


    /**
     * 全部已读-消息通知
     * @return
     */
    @SaCheckPermission("system:message:edit")
    @Log(title = "系统管理-消息通知", businessType = BusinessType.UPDATE)
    @PutMapping("/readAll")
    public R<Void> readAll() {
        return toAjax(sysMessageService.readAll());
    }
}
